import json
import os
import socket
from dataclasses import dataclass

hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)

# 当前目录下的logs文件夹
log_path = './logs'
if not os.path.exists(log_path):
    os.mkdir(log_path)  # 如果不存在这个logs文件夹，就自动创建一个

application_name = "YOUR_APP_NAME"

JSON_LOGGING_FORMAT = json.dumps(
    {"app_name": f"{application_name}", "level": "%(levelname)s", "logger": "%(module)s.%(funcName)s:%(lineno)d",
     "message": "%(message)s", "timestamp": "%(asctime)s.%(msecs)03d", "host": ip, "traceId": "%(thread)d"})

LOGGING = {
    "version": 1,
    "disable_existing_loggers": True,
    "formatters": {  # 日志输出样式
        "default": {
            "format": f"%(asctime)s.%(msecs)03dZ|{application_name}|%(thread)d|%(levelname)s|%(module)s.%(funcName)s:%(lineno)d|%(message)s",
            "datefmt": "%Y-%m-%d %H:%M:%S",
        },
        "file": {
            "format": JSON_LOGGING_FORMAT,
            "datefmt": "%Y-%m-%dT%H:%M:%S",
        }
    },
    "handlers": {
        "console": {
            "class": "logging.StreamHandler",  # 控制台输出
            "level": "DEBUG",
            "formatter": "default",
        },
        "log_file": {
            "class": "logging.handlers.RotatingFileHandler",
            "level": "INFO",
            "formatter": "file",  # 日志输出样式对应formatters
            'filename': f'{log_path}/{application_name}.log',  # 指定log文件目录
            "maxBytes": 20 * 1024 * 1024,  # 文件最大20M
            "backupCount": 10,  # 最多10个文件
            "encoding": "utf8",  # 文件编码
        },

    },
    "root": {
        "level": "INFO",  # # handler中的level会覆盖掉这里的level
        "handlers": ["console", "log_file"],
    }
}

@dataclass
class DB_CONFIG:
    HOST: str = '',
    USER: str ='',
    PASSWORD: str ='',
    DATABASE: str =''



LoginUserID = "LOGIN_USER_ID"
LoginUserCache = "LOGIN_USER_CACHE"

UserAuthHeader = "Authorization"
AdminAuthHeader = "Admin-Authorization"
ChatTokenHeader = "Chat-Token"

LIFESPAN = 60*60*2 # token过期时常设置
## 用于用户token
SECRET_KEY = ""


## oss 配置
OSS_KEY = ''
OSS_SECRET = ''
OSS_ENDPOINT = ''
OSS_BUCKET = ''
OSS_URL = ''

# REDIS 配置
REDIS_HOST = ""
REDIS_PORT = 6379
REDIS_pwd = ""
